//隐藏错误信息
function hideError() {
	$("#errorImg").attr("src", "images/shibai.gif");
	$("#errorMsg").text("错误信息:");
	$("#error").hide();
}

//校验身份证
function checkApInfoIdnum(obj) {
	if(IdCardValidate(obj.value)) {
		var idNum = obj.value;
		$.ajax({
	    	type:"post",//请求方式
	    	url:"safeCenter.do",//发送请求地址
	    	data:{//发送的数据
	    		m:"check_ai",
	    		idNum:idNum
	    	},
	    	dataType:"json",  
	    	//请求成功后的回调函数有两个参数
	    	success:function(data,textStatus){
	    		if(data.checkStr && "N"==data.checkStr){
	    			$("#apInfoIdnum").removeClass("Validform_error");
	    			$("#vc11").removeClass("Validform_right Validform_wrong");
	    			$("#vc11").text("通过信息验证！");
	    			$("#vc11").addClass("Validform_right");
	    		} else {
	    			$("#apInfoIdnum").addClass("Validform_error");
	    			$("#vc11").addClass("Validform_checktip Validform_wrong");
	    			$("#vc11").text("此身份证已经申请了实名认证，请您确认，如需帮助请联系妙购客服");
	    			return;
	    		}
	    	}
	    });
		
	} else {
		$("#apInfoIdnum").addClass("Validform_error");
		$("#vc11").addClass("Validform_checktip Validform_wrong");
		$("#vc11").text("请输入正确的身份证号码！");
		return;
	}
}

function subDataMain() {
	var sfz_flag = $("#sfz_flag").val();// 身份证校验状态为1：成功，0：失败
	var sfzimgFlag = document.getElementById("iframe_upload").document;
	if (sfzimgFlag == undefined) {
		var ofrm1 = document.getElementById("iframe_upload").contentWindow.document;
		sfzimgFlag = ofrm1.getElementById("sfzimgFlag");
    } else {
    	sfzimgFlag = document.frames["iframe_upload"].document.getElementById("sfzimgFlag");
    }
	
	var sfzimgFlagVal = "1";//默认为1，身份证相片可以不传，2013-3-7修改
	if (sfzimgFlag == null) {
		//$("#iframe_upload").contents().find("#btn_upload").click();//jquery 方法1
		//return;
	} else {
		sfzimgFlagVal = sfzimgFlag.value;
	}
	if (1 == sfz_flag && "1" == sfzimgFlagVal) {
		$("#sfzYear").removeClass("Validform_error");
		$("#sfzMonth").removeClass("Validform_error");
		$("#sfzDay").removeClass("Validform_error");
		$("#vc1").removeClass("Validform_right Validform_wrong");

		document.forms["form_main"].action = "safeCenter.do?m=bank";
		document.forms["form_main"].submit();

	} else {
		$("#vc1").text("请输入身份证到期时间！");
		$("#sfzYear").addClass("Validform_error");
		$("#sfzMonth").addClass("Validform_error");
		$("#sfzDay").addClass("Validform_error");
		$("#vc1").addClass("Validform_checktip Validform_wrong");
		return;
	}
}

function changeSfzState(obj) {
	if (obj.checked) {
		obj.value = "1";
		changeSfzState2();
	} else {
		obj.value = "0";
		$("#sfzYear").removeAttr("disabled");
		$("#sfzMonth").removeAttr("disabled");
		$("#sfzDay").removeAttr("disabled");
		$("#sfz_flag").val(0);// 身份证校验状态为1：成功，0：失败
	}
}

function changeSfzState2() {
	$("#sfzYear").removeClass("Validform_error");
	$("#sfzMonth").removeClass("Validform_error");
	$("#sfzDay").removeClass("Validform_error");
	$("#vc1").removeClass("Validform_right Validform_wrong");
	document.getElementById("vc1").innerHTML = "";
	
	$("#sfzYear").val("2012");
	$("#sfzMonth").val("01");
	$("#sfzDay").val("01");
	$("#sfzYear").attr("disabled", "disabled");
	$("#sfzMonth").attr("disabled", "disabled");
	$("#sfzDay").attr("disabled", "disabled");
	
	$("#sfz_flag").val(1);// 身份证校验状态为1：成功，0：失败
}



function convertSpace(obj) {
	var val = $.trim(obj.value).replace(/\s/g, '');

	var val2 = "";
	var len = 0;
	for ( var i = 0; i < val.length; i++) {
		var ch = val.charAt(i);
		if (ch >= 0 && ch <= 9) {
			val2 += ch;
			++len;
			if (len % 4 == 0) {
				val2 += ' ';
			}
		}
	}

	if (val2.substring(val2.length - 1, val2.length) == ' ') {
		val2 = val2.substring(0, val2.length - 1);
	}

	if (obj.value != val2) {
		var pos = getPositionForInput(obj);
		obj.value = val2;
		if (pos != val2.length) {
			if (val2.charAt(pos - 1) == ' ') {
				pos++;
			}
			setPositionForInput(obj, pos);
		}
	}
}

function goBackAttest() {
	document.forms["form_bank"].action = "safeCenter.do?navi=20&m=to_attest";
	document.forms["form_bank"].submit();
}

function goBackAttestBank() {
	document.forms["form_affirm"].action = "safeCenter.do?m=bank";
	document.forms["form_affirm"].submit();
}

/**
 * 离开手机输入框时触发事件
 */
function OnBlurFun(element, elementvalue) {
	if (element.value == "" || element.value.replace(/\s/g, "") == "") {
		element.value = elementvalue;
		element.style.color = "#888";
	} else {
		$("#sfz_flag").val(1);// 身份证校验状态为1：成功，0：失败
	}
}

$(function() {
	$("#qwe1").mouseover(function() {
		$("#qwe2").show(200);
	});

	$("#qwe1").mouseout(function() {
		$("#qwe2").hide(200);
	});
});

$(function() {
	$("#qwe3").mouseover(function() {
		$("#qwe4").show(200);
	});

	$("#qwe3").mouseout(function() {
		$("#qwe4").hide(200);
	});
});

function www_zzjs_net(BankNo) {
	if (BankNo.value == "")
		return;
	var account = new String(BankNo.value);
	account = account.substring(0, 22); /* 帐号的总数, 包括空格在内 */
	if (account.match(".[0-9]{4}-[0-9]{4}-[0-9]{4}-[0-9]{7}") == null) {
		/* 对照格式 */
		if (account.match(".[0-9]{4}-[0-9]{4}-[0-9]{4}-[0-9]{7}|"
				+ ".[0-9]{4}-[0-9]{4}-[0-9]{4}-[0-9]{7}|"
				+ ".[0-9]{4}-[0-9]{4}-[0-9]{4}-[0-9]{7}|"
				+ ".[0-9]{4}-[0-9]{4}-[0-9]{4}-[0-9]{7}") == null) {
			var accountNumeric = accountChar = "", i;
			for (i = 0; i < account.length; i++) {
				accountChar = account.substr(i, 1);
				if (!isNaN(accountChar) && (accountChar != " "))
					accountNumeric = accountNumeric + accountChar;
			}
			account = "";
			for (i = 0; i < accountNumeric.length; i++) { /* 可将以下空格改为-,效果也不错 */
				if (i == 4)
					account = account + "-"; /* 帐号第四位数后加空格 */
				if (i == 8)
					account = account + "-"; /* 帐号第八位数后加空格 */
				if (i == 12)
					account = account + "-";/* 帐号第十二位后数后加空格 */
				account = account + accountNumeric.substr(i, 1)
			}
		}
	} else {
		account = " " + account.substring(1, 5) + " "
				+ account.substring(6, 10) + " " + account.substring(14, 18)
				+ "-" + account.substring(18, 25);
	}
	if (account != BankNo.value)
		BankNo.value = account;
}
function checkBankNo(BankNo) {
	if (BankNo.value == "")
		return;
	if (BankNo.value.match(".[0-9]{4}-[0-9]{4}-[0-9]{4}-[0-9]{7}") == null) {
		if (BankNo.value.match("[0-9]{19}") != null)
			www_zzjs_net(BankNo)
	}
}
function checkEnterForFindListing(e) {
	var characterCode;
	if (e && e.which) {
		e = e;
		characterCode = e.which;
	} else {
		e = event;
		characterCode = e.keyCode;
	}
	if (characterCode == 22) {
		document.forms[getNetuiTagName("findListingForm")].submit();
		return false;
	} else {
		return true;
	}
}